package com.lams.service.system.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.lams.jdbc.IBaseDAO;
import com.lams.jdbc.QueryUtils;
import com.lams.service.BaseFacade;
import com.lams.service.system.IRoleFacade;
import com.lams.service.system.IUserFacade;
import com.lams.util.Encrypt_MD5;
import com.lams.util.ResultEntity;
import com.opensymphony.xwork2.ActionContext;

public class UserFacade extends BaseFacade implements IUserFacade {
	/**
	 * 
	 */
	private static final long serialVersionUID = -2253139728322578247L;
	private String queryUserListByRole;
	private String login;
	private IRoleFacade rf;
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public String login(Map params) {
//		Map params = new HashMap();
//		params.put(SUser.USERNO, u.getUserNo());
	//	params.put("PASSWORD", Encrypt_MD5.encrypt((String)params.get("PASSWORD")));
		String sql = QueryUtils.getSqlBySqlCode(login, params);
		List<Map> result = QueryUtils.executeQuery(sql);
		if(result.size()==1){
			Map map = ActionContext.getContext().getSession();
			Map item = result.get(0);
			map.put("user", item);
			map.put("role", this.getRole((String)item.get("USER_ID")));
		//	params.put("USER_ID", Integer.parseInt((String)item.get("USER_ID")));
			return "success";
		}
		return "input";
	}

	@Override
	public ResultEntity operateUser(String rid) {
		Map params = new HashMap();
		params.put("ROLE_ID", rid);
		String sql = QueryUtils.getSqlBySqlCode(queryUserListByRole, params);
		List data = QueryUtils.executeQuery(sql);
		ResultEntity result = new ResultEntity();
		result.setData(data);
		result.setTotalCount(data.size());
		result.setSuccess(true);
		result.setMessage("操作成功");
		return result;
	}

	@Override
	public List<Integer> getRole(String uid) {
		return rf.gerRoleIdByUserId(uid);
	}

	public String getQueryUserListByRole() {
		return queryUserListByRole;
	}

	public void setQueryUserListByRole(String queryUserListByRole) {
		this.queryUserListByRole = queryUserListByRole;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public IRoleFacade getRf() {
		return rf;
	}

	public void setRf(IRoleFacade rf) {
		this.rf = rf;
	}

}
